package uscdb.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import uscdb.pageModel.DataGrid;
import uscdb.pageModel.Json;
import uscdb.pageModel.Larea;
import uscdb.pageModel.PageHelper;
import uscdb.service.AreaServiceI;

/**
 * 区域控制器
 * 
 * @author SYSTEM
 *
 */
@Controller
@RequestMapping("/areaController")
public class AreaController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(AreaController.class);

	@Autowired
	private AreaServiceI areaService;

	@RequestMapping("/add")
	@ResponseBody
	public Json add(Larea larea) {
		Json json = new Json();
		try {
			areaService.add(larea);
			json.setSuccess(true);
			json.setMsg("添加成功！");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(Larea larea) {
		Json json = new Json();
		try {
			areaService.edit(larea);
			json.setSuccess(true);
			json.setMsg("修改成功！");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String ids) {
		Json json = new Json();
		try {
			json = areaService.delete(ids);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(Larea larea, PageHelper ph) {
		return areaService.dataGrid(larea, ph);
	}

	@RequestMapping("/manager")
	public String manager(HttpServletRequest request) {
		return "/project/area";
	}

	@RequestMapping("/areaCombobox")
	@ResponseBody
	public List<Larea> areaCombobox(String q) {
		List<Larea> lareaList = areaService.areaCombobox(q);
		return lareaList;
	}

}
